package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"

	cent "gitee.com/shuokeyun/common/ent"
)

type OrderBarcode struct {
	ent.Schema
}

func (OrderBarcode) Mixin() []ent.Mixin {
	return []ent.Mixin{
		cent.OrmMixin{},
	}
}

func (OrderBarcode) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{
			Table: "sk_order_barcode",
		},
	}
}

func (OrderBarcode) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("order_id").Comment("订单id"),
		field.Int32("brand").Immutable().Comment("品牌id"),
		field.String("barcode").Comment("条码"),
		field.Time("sampling_time").Optional().Nillable().Comment("采样时间"),
		field.String("consumable").Comment("耗材"),
		field.Int8("number").Default(1).Comment("耗材数量"),
		field.Int8("status").Default(-1).Comment("条码状态 -1待签收;1检测中;2拒绝签收;3检测失败;4报告已出"),
		field.Int8("report_status").Default(-1).Comment("报告状态 -1未出;1全部已出;2部分已出"),
		field.Time("report_time").Optional().Nillable().Comment("最后出报告时间"),
	}
}

func (OrderBarcode) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("order", Order.Type).Ref("barcodes").Unique().Required().Field("order_id"),
		edge.To("items", OrderItem.Type),
	}
}
